#!/bin/bash

function error() {
    local date=$(date)
    local para=$1
    echo -e "\033[31m[$date] error : $para \033[0m"
}

function info() {
    local date=$(date)
    local para=$1
    echo -e "\033[32m[$date] info : $para \033[0m"
}

function do_install() {
    cd /tmp
    info "start install galaxy sdk ..."
    platform=''
    addr=''
    hostnamectl | grep -i "Architecture: x86"
    if [ $? -ne 0 ]; then
        hostnamectl | grep -i "Architecture: arm"
        if [ $? -ne 0 ]; then
            exit 1
        fi
        info "is arm!"
        wget http://gb.daheng-imaging.com/CN/Software/Cameras/Linux/Galaxy_Linux-armhf_Gige-U3_32bits-64bits_1.3.2107.9261.tar.gz
        tar -xzvf Galaxy_Linux-armhf_Gige-U3_32bits-64bits_1.3.2107.9261.tar.gz
        cd Galaxy_Linux-armhf_Gige-U3_32bits-64bits_1.3.2107.9261
        sudo ./Galaxy_camera.run
    else
        info "is x86"
        wget http://gb.daheng-imaging.com/CN/Software/Cameras/Linux/Galaxy_Linux-x86_Gige-U3_32bits-64bits_1.2.2107.9261.tar.gz
        tar -xzvf Galaxy_Linux-x86_Gige-U3_32bits-64bits_1.2.2107.9261.tar.gz
        cd Galaxy_Linux-x86_Gige-U3_32bits-64bits_1.2.2107.9261
        sudo ./Galaxy_camera.run
    fi
}

main() {
    do_install
}

main "$@"
